import java.awt.Image;
import java.awt.Toolkit;
import java.io.File;

import javax.swing.JFileChooser;
import javax.swing.JOptionPane;

import com.apple.eawt.Application;

import Resources.*;
import Model.XMLManager;
import Viewer.ExitView;
import Viewer.MainWindow;
import Controller.ExitController;
import Controller.XMLController;


public class Mainclass {

	public static void main(String[] args) {
	
		
				//set dell'icona MAC
		Application application = Application.getApplication();
		Image image = Toolkit.getDefaultToolkit().getImage((Mainclass.class.getResource("/Resources/Logo.png")));
		application.setDockIconImage(image);
		
		
		/**
		 * creazione dei controller e view
		 */
		
		XMLController controller = new XMLController();
		MainWindow window = new MainWindow(controller);
		final JFileChooser fc = new JFileChooser();
		
		
//		ExitController ExitController = new ExitController();
//		ExitView Exitwindow = new ExitView(ExitController);
		
		/**
		 * Carico il mio canzoniere
		 * 
		 */
		String path = "Songs.xml";
		File f2 = new File(path);
		
		String chordsPath = "Chords.xml";
		File f3 = new File(chordsPath);
		
		String SettingsPath = "Settings.xml";
		File f1 = new File(SettingsPath);
		
		//TODO: sistemare le condizioni per il primo caricamento
		String message = "I seguenti files di salvataggio non sono stati trovati:\n\n";
		String messageADD ="";
		
		
		if (!f2.exists()) {			
			messageADD = messageADD + "Songs.xml\n";			
			path="";
			
		}
		if (!f3.exists()) {			
			messageADD = messageADD + "Chords.xml\n";
			chordsPath="";
			
		}
		
		if (!f1.exists()) {			
			
		window.saveDefaultSettings();	
			
		}
		else{
			window.loadSettings();
		}
		
			
			controller.mainLoad(path,chordsPath);
		
		if(!messageADD.equals("")){
			String show = message+messageADD;
		JOptionPane
		.showMessageDialog(
				null,
				show,
				"Attenzione", JOptionPane.WARNING_MESSAGE);
		}
		
		
		
		System.out.println("Ho terminato il Main ---Attendo Thread Figli");
		

	}

}
